package com.hexus.eve.actions.security;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;


import com.hexus.eve.entities.security.SecurityGroup;
import com.opensymphony.xwork2.ActionSupport;

public class DeleteGroup extends ActionSupport {
	private static final long serialVersionUID = 1L;
	
	@Autowired
	private SessionFactory sessionFactory;
	private Integer securityGroupId;
	
	@Override
	public String execute() throws Exception {
		HibernateTemplate ht = new HibernateTemplate(sessionFactory);
		SecurityGroup securityGroup;
		
		//Update or creation of a new item
		if(securityGroupId != null) {
			securityGroup = ht.get(SecurityGroup.class, securityGroupId);
			if(securityGroup != null) {
				ht.delete(securityGroup);
			}
		}
		return SUCCESS;
	}

	public Integer getSecurityGroupId() {
		return securityGroupId;
	}

	public void setSecurityGroupId(String securityGroupId) {
		if(securityGroupId != null && !"".equals(securityGroupId))
			this.securityGroupId = Integer.parseInt(securityGroupId);
	}
}
